package com.kandinfo.survey.common.service.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kandinfo.base.common.service.AbstractService;
import com.kandinfo.base.security.domain.User;
import com.kandinfo.survey.common.constants.StatusConstant;
import com.kandinfo.survey.common.domain.UserAnswerDetail;
import com.kandinfo.survey.common.domain.UserAnswerInfo;
import com.kandinfo.survey.common.dto.useranswer.UserAnswerRequestDto;
import com.kandinfo.survey.common.repository.UserAnswerDetailRepository;
import com.kandinfo.survey.common.service.UserAnswerDetailService;

@Service
public class UserAnswerDetailServiceImpl extends AbstractService<UserAnswerDetail, Long, UserAnswerDetailRepository>
        implements UserAnswerDetailService {

    @Resource
    public void setUserAnswerDetailRepository(UserAnswerDetailRepository userAnswerDetailRepository) {
        super.setRepository(userAnswerDetailRepository);
    }

    @Override
    @Transactional
    public void saveUserAnswerDetail(User curUser, UserAnswerRequestDto requestDto, UserAnswerInfo info) {
        UserAnswerDetail detail = new UserAnswerDetail();
        detail.setCreateBy(curUser.getId());
        detail.setCreateTs(new Date());
        detail.setInfoId(info.getId());
        detail.setAnswerContent(requestDto.getAnswerContent());
        detail.setQuestionId(requestDto.getQuestionId());
        detail.setOptionId(requestDto.getOptionId());
        detail.setNeedAlarm(requestDto.getNeedAlarm());
        detail.setStatus(StatusConstant.NORMALLY_USE);

        repository.save(detail);
    }

}
